﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Security.Principal;
using System.Xml;
using System.IO;
using System.Management;

using Microsoft.Win32;
//using System.Data.Sql;



namespace MegaSetting
{
    public partial class frmMain : Form
    {
        
        public frmMain()
        {
            InitializeComponent();
        }
        
        private string strCurrentAccountName;
        private string strCurrentAccountSID;
        private string strAdminAccountSID;
        private DataTable tblPointData=new DataTable ();
        private DataTable tblPointConfig = new DataTable();

        private bool boolIsFirstRun;

        private void SavePointConfig() 
        {

            /*
            PointData.Columns.Add("PointCode");
            PointData.Columns.Add("SbcliCode");
            PointData.Columns.Add("PointName");
            PointData.Columns.Add("GatewayIP");
            tblPointConfig.Columns.Add("PointCode");
            tblPointConfig.Columns.Add("SubMask");
            tblPointConfig.Columns.Add("GatewayIP");
            tblPointConfig.Columns.Add("MachineIP");
            tblPointConfig.Columns.Add("IsManager");
            tblPointConfig.Columns.Add("IsServer");             

            tblPointConfig.WriteXmlSchema("d:\\PointConfigSchema.xml");
            tblPointConfig.WriteXml("d:\\PointConfig.xml");
*/


            //tblPointConfig.ReadXmlSchema(Application.StartupPath + "\\PointConfigSchema.xml");
            tblPointConfig.Rows.Clear();// tblPointConfig.Rows.RemoveAt(0);
            tblPointConfig.Rows.Add(txtPointCode.Text, txtSubMask.Text, txtGatewayIP.Text, txtLocalIP.Text, chkDatabase.Checked ? "1" : "0", chkManager.Checked ? "1" : "0", txtLocalServerIP.Text, txtSbcliSvcIP.Text, txtUpdateServerIP.Text, txtDistrictIP.Text);
            tblPointConfig.WriteXml("d:\\Settings Backup\\PointConfig.xml");

            //


        }

        private void LoadPointConfig() 
        {
            //tblPointConfig.Rows.Add(txtPointCode.Text, txtSubMask.Text, txtLocalIP.Text, chkDatabase.Checked ? "1" : "0", chkManager.Checked ? "1" : "0");
            tblPointConfig.ReadXml("d:\\Settings Backup\\PointConfig.xml");
            txtPointCode.Text = tblPointConfig.Rows[0].ItemArray[0].ToString ();
            txtSubMask.Text =tblPointConfig.Rows[0].ItemArray[1].ToString ();
            txtGatewayIP .Text  =tblPointConfig.Rows[0].ItemArray[2].ToString ();
            txtLocalIP .Text =tblPointConfig.Rows[0].ItemArray[3].ToString ();
            chkDatabase.Checked  =(tblPointConfig.Rows[0].ItemArray[4].ToString ()=="1");
            chkManager.Checked = (tblPointConfig.Rows[0].ItemArray[5].ToString() == "1");
            txtLocalServerIP.Text = tblPointConfig.Rows[0].ItemArray[6].ToString();
            txtSbcliSvcIP .Text =tblPointConfig.Rows[0].ItemArray[7].ToString();
            txtUpdateServerIP.Text = tblPointConfig.Rows[0].ItemArray[8].ToString();
            txtDistrictIP.Text = tblPointConfig.Rows[0].ItemArray[9].ToString();
        }

        private void btnStart_Click(object sender, EventArgs e)
        {

            //if(tblPointConfig .Rows .Count ==0)SavePointConfig();
            SavePointConfig();


            //第一次运行
            if (boolIsFirstRun) 
            {



                //创建监控配置文件

                txtLog.Text += ExecuteShellAndGetResult("attrib", @"c:\windows\system32\sbclisvc.ini -s -a");
                using (StreamWriter sw = new StreamWriter(Environment .SystemDirectory  + @"\sbclisvc.ini",false))
                {
                    sw.WriteLine("[SBCliSvc]");
                    txtLog.Text +="[SBCliSvc]\r\n";

                    sw.WriteLine("VERSION = 32");
                    txtLog.Text += "VERSION = 32\r\n";

                    //tblPointConfig .


                    if (txtGatewayIP.Text.Substring(0, 3) == "198")
                    {
                        sw.WriteLine("SERVER_IP = 133.171.0.203");
                        txtLog.Text += "SERVER_IP = 133.171.0.203\r\n";                        
                    }
                    else
                    {
                        sw.WriteLine("SERVER_IP = 10.102.86.12");
                        txtLog.Text += "SERVER_IP = 10.102.86.12\r\n";    
                    }

                    sw.WriteLine("SERVER_PORT = 8341");
                    txtLog.Text +="SERVER_PORT = 8341\r\n" ;

                    sw.WriteLine("HOST_ID = " + txtLocalIP.Text.Substring(txtLocalIP.Text.Length - 1, 1));
                    txtLog.Text += "HOST_ID = " + txtLocalIP.Text.Substring(txtLocalIP.Text.Length - 1, 1)+"\r\n";

                    sw.WriteLine("STATION_ID = " + txtSbcliCode.Text.Substring(txtSbcliCode.Text.Length - 2, 2));
                    txtLog.Text += "STATION_ID = " + txtSbcliCode.Text.Substring(txtSbcliCode.Text.Length - 2, 2)+"\r\n";

                    sw.WriteLine("DISTRICT_ID = " + txtSbcliCode.Text.Substring(0, txtSbcliCode.Text.Length - 2));
                    txtLog.Text +="DISTRICT_ID = " + txtSbcliCode.Text.Substring(0, txtSbcliCode.Text.Length - 2)+"\r\n";
 
                    sw.WriteLine("INTERVAL_TIME = 5000");
                    txtLog.Text +="INTERVAL_TIME = 5000\r\n";
                    sw.Close();

                }
                

                //设置防火墙端口
                txtLog.Text += "*添加端口：\t 3306 \r\n";
                txtLog.Text += ExecuteShellAndGetResult("netsh.exe", "firewall add portopening tcp 3306 MySQL");
                Application.DoEvents();

                txtLog.Text += "*添加端口：\t 798 \r\n";
                txtLog.Text += ExecuteShellAndGetResult("netsh.exe", "firewall add portopening tcp 798 CA");
                Application.DoEvents();
                

                //创建临时帐户
                txtLog.Text += "*创建帐户: Manager \r\n";
                txtLog.Text += ExecuteShellAndGetResult("net.exe", "user Manager /add");
                Application.DoEvents();

                txtLog.Text += "*设置账户组 \r\n";
                txtLog.Text += ExecuteShellAndGetResult("net.exe", "localgroup administrators Manager /add");
                Application.DoEvents();

                txtLog.Text += "*设置自动登录：\tManager \r\n";
                Application.DoEvents();
                txtLog.Text += ExecuteShellAndGetResult("reg.exe", "add \"hklm\\software\\microsoft\\windows nt\\currentversion\\winlogon\" /v defaultusername /d Manager /f");

                //网络配置
                SetNetworkAdapter(txtLocalIP.Text, txtSubMask.Text, txtGatewayIP.Text, txtMainDNS.Text, txtSubDNS.Text);

                txtLog.Text += "*重启! \r\n";
                txtLog.Text += ExecuteShellAndGetResult("shutdown", "-r -t 0");
            }
            else 
            {
                //第二次运行
                if (  strCurrentAccountName.ToLower().IndexOf("manager") != -1)
                {
                    txtLog.Text += "*删除临时文件夹：\tTemp \r\n";
                    Application.DoEvents();
                    txtLog.Text += ExecuteShellAndGetResult("cmd", "/c rmdir \"C:\\Documents and Settings\\Administrator\\Local Settings\\Temp\" /s /q");

                    txtLog.Text += "*移动个人文件夹到：\tD盘 \r\n";
                    Application.DoEvents();
                    txtLog.Text += ExecuteShellAndGetResult("xcopy", "\"C:\\Documents and Settings\\Administrator\\*.*\" \"D:\\Documents and Settings\\Administrator\\\" /e /h /y");

                    txtLog.Text += "*设置个人文件夹到：\tD盘 \r\n";
                    Application.DoEvents();
                    txtLog.Text += ExecuteShellAndGetResult("reg.exe", "add \"hklm\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\" + strAdminAccountSID + "\" /v ProfileImagePath /d \"D:\\Documents and Settings\\Administrator\" /f");

                    txtLog.Text += "*设置自动登录：\t Administrator \r\n";
                    Application.DoEvents();
                    txtLog.Text += ExecuteShellAndGetResult("reg.exe", "add \"hklm\\software\\microsoft\\windows nt\\currentversion\\winlogon\" /v defaultusername /d Administrator /f");

                    txtLog.Text += "*重启! \r\n";
                    txtLog.Text += ExecuteShellAndGetResult("shutdown", "-r -t 0");
                }
                //第三次运行 删除临时帐户
                else if (strCurrentAccountName.ToLower ().IndexOf("administrator")!=-1)
                {

                    //复制网点程序
                    txtLog.Text += "*复制网点程序: SHJZZ \r\n";
                    //Directory.CreateDirectory("d:\\shjzz\\");
                    //File.Copy (Application.StartupPath +"\\shjzz.exe","d:\\shjzz\\shjzz.exe");
                    txtLog.Text += ExecuteShellAndGetResult(Application .StartupPath +"\\shjzz.exe","/S");
                    Application.DoEvents();

                    txtLog.Text += "*配置网点程序：SHJZZ\r\n";
                    //txtLog .Text +=ExecuteShellAndGetResult ("reg add hklm\software\microsoft\windows\currentversion\run /v "MegaSetting" /t REG_SZ /d "%SystemDrive%\Preinstall\MegaSetting.exe")



                    RegistryKey key = Registry.LocalMachine.OpenSubKey("SOFTWARE", true);
                    key.CreateSubKey("SHJZZ");
                    key = key.OpenSubKey("SHJZZ", true);
                    key.CreateSubKey("POINT");
                    key = key.OpenSubKey("POINT", true);
                    if (chkManager. Checked)
                    {
                        key.SetValue("type", "1");                        
                    }
                    else
                    {
                        key.SetValue("type", "0");
                    }

                    key.CreateSubKey("D_shjzz");
                    key = key.OpenSubKey("D_shjzz", true);
                    key.SetValue("pointid",tblPointConfig.Rows[0].ItemArray[0].ToString ());
                    key.SetValue("pointport", "3306");
                    key.SetValue("pointserver", tblPointConfig.Rows[0].ItemArray[6].ToString());
                    key.SetValue("serverip", (tblPointConfig .Rows[0].ItemArray [2].ToString ().Substring (0,3)=="198")?"133.171.100.12":"10.102.86.10");
                    key.SetValue("serverport", "7001");
                    key.SetValue("countyserverip", txtDistrictIP.Text );
                    key.SetValue("countyserverport", "8001");
                    key.SetValue("reportalertinterval", "1");
                    key.SetValue("reportinterval", "1");
                    key.SetValue("reportnumber", "10");
                    key.SetValue("uploadinterval", "1");
                    key.SetValue("uploadintervalcounty", "3");
                    key.SetValue("uploadintervalsbk", "2");
                    key.SetValue("uploadintervalsbkpic", "3");
                    key.SetValue("uploadnumber", "10");
                    key.SetValue("uploadnumbercounty", "10");
                    key.SetValue("uploadnumbersbk", "10");
                    key.SetValue("uploadnumbersbkpic", "10");

                    

                    //p

                    txtLog.Text += "*删除启动项：\t MegaSetting \r\n";
                    Application.DoEvents();
                    txtLog.Text += ExecuteShellAndGetResult("reg.exe", "delete hklm\\software\\microsoft\\windows\\currentversion\\run /v \"MegaSetting\" /f");


                    txtLog.Text += "*删除帐户：\t Manager \r\n";
                    txtLog.Text += ExecuteShellAndGetResult("net.exe", "user Manager /delete");
                    Application.DoEvents();

                    txtLog.Text += "*删除个人文件夹：\t Manager \r\n";
                    txtLog.Text += ExecuteShellAndGetResult("cmd", "/c rmdir \"C:\\Documents and Settings\\Manager\" /s /q");
                    Application.DoEvents();

                    txtLog.Text += "*删除个人文件夹: Administrator \r\n";
                    txtLog.Text += ExecuteShellAndGetResult("cmd", "/c rmdir \"C:\\Documents and Settings\\Administrator\" /s /q");
                    Application.DoEvents();

                    //配置输入法
                    // ExecuteShellAndGetResult(Application.StartupPath +@"\psgetsid.exe", "administrator");
                    txtLog.Text += "*添加输入法：\t 极品五笔\r\n";
                    Process.Start(Application.StartupPath + @"\imetool.exe", "/install:jpwb.ime /install:jwz.ime /install:sjm.ime");
                    //Process.Start(Application.StartupPath + @"\imetool.exe", "/add2:jpwb.ime");

                    txtLog.Text += "*添加输入法：\t 集外字\r\n";
                    //Process.Start(Application.StartupPath + @"\imetool.exe", "/install:jwz.ime");
                    //Process.Start(Application.StartupPath + @"\imetool.exe", "/add2:jwz.ime");

                    txtLog.Text += "*添加输入法：\t 三角码\r\n";
                    //Process.Start(Application.StartupPath + @"\imetool.exe", "/install:sjm.ime");
                    //Process.Start(Application.StartupPath + @"\imetool.exe", "/add2:sjm.ime");


                    /*
                     * 
                     * server=133.171.100.81

                     */
                    //FileStream fs= File.Open (@"d:\shjzz\client.ini", FileMode.Create);

                    string strConfigString = "[config]\r\n";
                    if ( (tblPointConfig .Rows[0].ItemArray [2].ToString ().Substring (0,3)=="198"))
                    {
                        strConfigString+="server=133.171.100.81\r\n"; 
                    }
                    else
                    {
                        strConfigString+="server=10.102.86.21\r\n"; 

                    }
                    strConfigString+="port=8080\r\nentry=update.update\r\n[port]\r\nIC4=1\r\nKEY=1\r\n[device]\r\nCOM1=3\r\nUSBPOS=0\r\nTYPE=3";

                    File.WriteAllText(@"d:\shjzz\client.ini", strConfigString);
                    

                    txtLog.Text += "**全部完成!";

                    btnStart.Enabled = false;
                
                }

            }

            //Application.Exit();
        }

        private string ExecuteShellAndGetResult(string filename, string arguments)
        {
            //实例化一个进程类
            Process cmd = new Process();
            string ret;

            cmd.StartInfo.FileName = filename;
            cmd.StartInfo.Arguments = arguments;

            //将cmd的标准输入和输出全部重定向到.NET的程序里

            cmd.StartInfo.UseShellExecute = false; //此处必须为false否则引发异常

            cmd.StartInfo.RedirectStandardInput = true; //标准输入
            cmd.StartInfo.RedirectStandardOutput = true; //标准输出

            //不显示命令行窗口界面
            cmd.StartInfo.CreateNoWindow = true;
            cmd.StartInfo.WindowStyle = ProcessWindowStyle.Normal;

            cmd.Start(); //启动进程

            //获取输出
            //需要说明的：\t此处是指明开始获取，要获取的内容，
            //只有等进程退出后才能真正拿到
            ret = cmd.StandardOutput.ReadToEnd();

            cmd.WaitForExit();//等待控制台程序执行完成
            cmd.Close();//关闭该进程

            return ret;
        }


        private void GetEnvironments() 
        {
            WindowsIdentity m_Self = WindowsIdentity.GetCurrent();
            strCurrentAccountName = m_Self.Name;

            SecurityIdentifier m_SID = m_Self.Owner;
            strCurrentAccountSID = m_SID.Value;

            string strAdminSID = ExecuteShellAndGetResult(Application.StartupPath +@"\psgetsid.exe", "administrator");
            strAdminAccountSID = strAdminSID.Substring(strAdminSID.IndexOf(":") + 3);
            strAdminAccountSID = strAdminAccountSID.TrimEnd(new char[] { '\r', '\n' });
            txtLog.Text +="管理员 SID：\t" + strAdminAccountSID+"\r\n";

            string strAllUsers = ExecuteShellAndGetResult("net", "user");
            //not found manager account
            if (strAllUsers.IndexOf("Manager") == -1)
            {
                boolIsFirstRun = true;

            }
            else 
            {
                boolIsFirstRun = false;
            }
        }

        private void txtLog_TextChanged(object sender, EventArgs e)
        {
            txtLog.SelectionStart = txtLog.TextLength-1;
            txtLog.ScrollToCaret();
        }

        private void chkDatabase_CheckedChanged(object sender, EventArgs e)
        {
            chkManager.Checked = chkDatabase .Checked ;
            
           
        }


        static void SetNetworkAdapter(string IPAddress,string SubnetMask,string GatewayIP,string MainDNSIP,string SubDNSIP)
        {
            ManagementBaseObject inPar = null;
            ManagementBaseObject outPar = null;
            ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
            ManagementObjectCollection moc = mc.GetInstances();
            foreach (ManagementObject mo in moc)
            {
                if (!(bool)mo["IPEnabled"])
                    continue;

                //设置ip地址和子网掩码 
                inPar = mo.GetMethodParameters("EnableStatic");
                inPar["IPAddress"] = new string[] { IPAddress };// 1.备用 2.IP
                inPar["SubnetMask"] = new string[] { SubnetMask };
                outPar = mo.InvokeMethod("EnableStatic", inPar, null);

                //设置网关地址 
                inPar = mo.GetMethodParameters("SetGateways");
                inPar["DefaultIPGateway"] = new string[] { GatewayIP }; // 1.网关;2.备用网关
                outPar = mo.InvokeMethod("SetGateways", inPar, null);

                //设置DNS 
                inPar = mo.GetMethodParameters("SetDNSServerSearchOrder");
                inPar["DNSServerSearchOrder"] = new string[] { MainDNSIP, SubDNSIP }; // 1.DNS 2.备用DNS
                outPar = mo.InvokeMethod("SetDNSServerSearchOrder", inPar, null);
                break;
            }
        }



        private void ReadXML() 
        {
            string[] strTmps = new string[65535];
            string strTmp;
            FileStream fStream = new FileStream(Application.StartupPath +@"\point.txt",FileMode.Open  );
            byte[] bytTmp = new byte[65536];
            fStream.Read(bytTmp, 0, (int)fStream.Length);
            strTmp = Encoding.Default.GetString(bytTmp).Replace("\r\n", "\n").Replace(" ", "").Replace("(SP75)", "").Replace("(SP75P)", "").Replace("?", "");
            strTmps = strTmp.Split('\n');
            DataTable PointData = new DataTable("PointData");
            
            PointData.Columns.Add("PointCode");
            PointData.Columns.Add("SbcliCode");
            PointData.Columns.Add("PointName");
            PointData.Columns.Add("GatewayIP");
            foreach (string itm in strTmps) 
            {
                //1010101	外滩街道（社保卡、居住证受理点）	12.120.110.190	401
                if (itm.Replace("\0", "").Length == 0) break;
                string gateip;
                gateip = itm.Split('\t').GetValue(2).ToString().Replace("政务网", "");
                if (gateip.Length == 0)
                {
                    
                }
                else 
                {
                    gateip = gateip.Substring(0, gateip.LastIndexOf('.'));
                    gateip += ".1";
                }

                PointData.Rows.Add(
                    itm.Split('\t').GetValue(0),
                    itm.Split('\t').GetValue(3),
                    itm.Split('\t').GetValue(1),
                    gateip );
            }




            //PointData.Rows.Add("1010101", "401", "外滩街道（社保卡、居住证受理点）", "12.120.110.1");
            
           //PointData.WriteXmlSchema (Application.StartupPath +@"\a.xml");
            //MessageBox.Show(PointData.Rows.Count.ToString());
            

        }

        private void txtPointCode_TextChanged(object sender, EventArgs e)
        {
            for (int i = 0; i < tblPointData.Rows.Count; i++) 
            {
                if (tblPointData.Rows[i].ItemArray[0].ToString() == txtPointCode.Text) 
                {
                    
                    if(txtSbcliCode .Text .Length ==0)txtSbcliCode.Text  = tblPointData.Rows[i].ItemArray[1].ToString();
                    labPointName .Text = tblPointData.Rows[i].ItemArray[2].ToString();
                    txtGatewayIP .Text =tblPointData.Rows[i].ItemArray[3].ToString();
                    txtDistrictIP.Text = tblPointData.Rows[i].ItemArray[4].ToString();

                    txtSubMask.Text = "255.255.255.0";
                    if (tblPointData.Rows[i].ItemArray[3].ToString().Length != 0) 
                    {
                        txtLocalIP.Text = tblPointData.Rows[i].ItemArray[3].ToString().Substring (0,tblPointData.Rows[i].ItemArray[3].ToString().LastIndexOf ('.')+1);
                        txtLocalServerIP.Text = txtLocalIP.Text;
                        
                    }

                    try
                    {
                        if (tblPointData.Rows[i].ItemArray[3].ToString().Substring(0, 3) == "198")
                        {
                            txtCenterServerIP.Text = "133.171.100.12";
                            txtSbcliSvcIP.Text = "133.171.0.203";
                            txtUpdateServerIP.Text = "133.171.100.81";
                        }
                        else
                        {
                            txtCenterServerIP.Text = "10.102.86.10";
                            txtSbcliSvcIP.Text = "10.102.86.12";
                            txtUpdateServerIP.Text = "10.102.86.21";
                        }
                    }
                    catch (Exception)
                    {
                        
                        //throw;
                    }
                    
                }

                
            }

            
        }

        private void frmMain_Load(object sender, EventArgs e)
        {

            this.Text += "  "+Application.ProductVersion;
            //ReadXML();
            tblPointConfig.ReadXmlSchema(Application.StartupPath + "\\PointConfigSchema.xml");
            
            tblPointData.ReadXmlSchema(Application.StartupPath + @"\PointDataSchema.xml");
            tblPointData.ReadXml(Application.StartupPath + @"\pointdata.xml");



            string strAllUsers = ExecuteShellAndGetResult("reg.exe", "add \"hkcu\\Software\\Sysinternals\\PsGetSid\" /v EulaAccepted /t REG_DWORD /d 1 /f");

            GetEnvironments();
            txtLog.Text += "当前帐户SID：\t" + strCurrentAccountSID + "\r\n";
            txtLog.Text += "当前帐户名称：\t" + strCurrentAccountName + "\r\n";
            txtLog.Text += "是第一次运行：\t" + boolIsFirstRun.ToString() + "\r\n";

            //read point config
            if (Directory.Exists("d:\\Settings Backup"))
            {
                if (File.Exists("d:\\Settings Backup\\PointConfig.xml"))
                {
                    LoadPointConfig();
                    if(!boolIsFirstRun) btnStart_Click(this, e);
                } 
            }
            else 
            {
                Directory.CreateDirectory("d:\\Settings Backup");
            }
        }


        private void txtLocalIP_TextChanged(object sender, EventArgs e)
        {
            if (chkDatabase.Checked)
            {
                txtLocalServerIP.Text = txtLocalIP.Text;
            }
            if (txtLocalIP.Text.Substring(txtLocalIP.Text.Length - 1, 1) != ".")
            {
                btnStart.Enabled = true;
            }
            else 
            {
                btnStart.Enabled = false;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //tblPointData.Columns.Add("DistrictIP");
            DataTable dt = new DataTable();
            dt.ReadXmlSchema(@"d:\dd.xml");
            //DataRow dr;

            for (int i = 0; i < tblPointData.Rows.Count; i++)
			{
                switch (tblPointData.Rows[i].ItemArray[1].ToString().Substring(0, (tblPointData.Rows[i].ItemArray[1].ToString().Length == 3) ? 1 : 2))
                {
                    case "1":
                        //tblPointData.Rows[i].ItemArray.SetValue (;
                        //MessageBox.Show( tblPointData.Rows[i].ItemArray.GetValue (1).ToString());
                        //MessageBox.Show(tblPointData.Rows[i].ItemArray [4].ToString ());



                        break;
                    case "2":
                        tblPointData.Rows[i].ItemArray[4] = "";
                        dt.Rows.Add(tblPointData.Rows[i].ItemArray[0], tblPointData.Rows[i].ItemArray[1], tblPointData.Rows[i].ItemArray[2], tblPointData.Rows[i].ItemArray[3], "10.201.2.39");

                        break;
                    case "3":
                        tblPointData.Rows[i].ItemArray[4] = "";
                        dt.Rows.Add(tblPointData.Rows[i].ItemArray[0], tblPointData.Rows[i].ItemArray[1], tblPointData.Rows[i].ItemArray[2], tblPointData.Rows[i].ItemArray[3], "10.208.250.10");

                        break;
                    case "4":
                        tblPointData.Rows[i].ItemArray[4] = "";
                        dt.Rows.Add(tblPointData.Rows[i].ItemArray[0], tblPointData.Rows[i].ItemArray[1], tblPointData.Rows[i].ItemArray[2], tblPointData.Rows[i].ItemArray[3], "10.221.175.32");

                        break;
                    case "5":
                        tblPointData.Rows[i].ItemArray[4] = "";
                        dt.Rows.Add(tblPointData.Rows[i].ItemArray[0], tblPointData.Rows[i].ItemArray[1], tblPointData.Rows[i].ItemArray[2], tblPointData.Rows[i].ItemArray[3], "10.223.110.241");

                        break;
                    case "6":
                        tblPointData.Rows[i].ItemArray[4] = "";
                        dt.Rows.Add(tblPointData.Rows[i].ItemArray[0], tblPointData.Rows[i].ItemArray[1], tblPointData.Rows[i].ItemArray[2], tblPointData.Rows[i].ItemArray[3], "10.220.0.80");

                        break;
                    case "7":
                        tblPointData.Rows[i].ItemArray[4] = "";
                        dt.Rows.Add(tblPointData.Rows[i].ItemArray[0], tblPointData.Rows[i].ItemArray[1], tblPointData.Rows[i].ItemArray[2], tblPointData.Rows[i].ItemArray[3], "198.141.12.2");

                        break;
                    case "8":
                        tblPointData.Rows[i].ItemArray[4] = "";
                        dt.Rows.Add(tblPointData.Rows[i].ItemArray[0], tblPointData.Rows[i].ItemArray[1], tblPointData.Rows[i].ItemArray[2], tblPointData.Rows[i].ItemArray[3], "10.214.67.101");

                        break;
                    case "9":

                        dt.Rows.Add(tblPointData.Rows[i].ItemArray[0], tblPointData.Rows[i].ItemArray[1], tblPointData.Rows[i].ItemArray[2], tblPointData.Rows[i].ItemArray[3], "198.141.13.2");

                        break;
                    case "10":

                        dt.Rows.Add(tblPointData.Rows[i].ItemArray[0], tblPointData.Rows[i].ItemArray[1], tblPointData.Rows[i].ItemArray[2], tblPointData.Rows[i].ItemArray[3], "10.236.10.20");

                        break;
                    case "11":

                        dt.Rows.Add(tblPointData.Rows[i].ItemArray[0], tblPointData.Rows[i].ItemArray[1], tblPointData.Rows[i].ItemArray[2], tblPointData.Rows[i].ItemArray[3], "198.141.11.205");

                        break;
                    case "12":

                        dt.Rows.Add(tblPointData.Rows[i].ItemArray[0], tblPointData.Rows[i].ItemArray[1], tblPointData.Rows[i].ItemArray[2], tblPointData.Rows[i].ItemArray[3], "10.237.0.32");

                        break;
                    case "13":

                        dt.Rows.Add(tblPointData.Rows[i].ItemArray[0], tblPointData.Rows[i].ItemArray[1], tblPointData.Rows[i].ItemArray[2], tblPointData.Rows[i].ItemArray[3], "10.207.100.5");

                        break;
                    case "14":

                        dt.Rows.Add(tblPointData.Rows[i].ItemArray[0], tblPointData.Rows[i].ItemArray[1], tblPointData.Rows[i].ItemArray[2], tblPointData.Rows[i].ItemArray[3], "10.233.255.11");

                        break;
                    case "15":

                        dt.Rows.Add(tblPointData.Rows[i].ItemArray[0], tblPointData.Rows[i].ItemArray[1], tblPointData.Rows[i].ItemArray[2], tblPointData.Rows[i].ItemArray[3], "10.234.0.10");

                        break;
                    case "16":

                        dt.Rows.Add(tblPointData.Rows[i].ItemArray[0], tblPointData.Rows[i].ItemArray[1], tblPointData.Rows[i].ItemArray[2], tblPointData.Rows[i].ItemArray[3], "10.235.1.3");

                        break;
                    case "17":

                        dt.Rows.Add(tblPointData.Rows[i].ItemArray[0], tblPointData.Rows[i].ItemArray[1], tblPointData.Rows[i].ItemArray[2], tblPointData.Rows[i].ItemArray[3], "10.242.0.252");

                        break;
                    case "18":

                        dt.Rows.Add(tblPointData.Rows[i].ItemArray[0], tblPointData.Rows[i].ItemArray[1], tblPointData.Rows[i].ItemArray[2], tblPointData.Rows[i].ItemArray[3], "10.244.251.10");

                        break;
                    case "19":

                        dt.Rows.Add(tblPointData.Rows[i].ItemArray[0], tblPointData.Rows[i].ItemArray[1], tblPointData.Rows[i].ItemArray[2], tblPointData.Rows[i].ItemArray[3], "10.232.3.124");

                        break;
                    default:
                        break;



                }


			    
			}
                MessageBox.Show(dt.Rows.Count.ToString () );
                dt.WriteXml("d:\\a.xml");
                dt.WriteXmlSchema(@"d:\dt.xml");
        }













    }
}
